<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>产品采购退货管理</title>
</head>
<body>
<style type="text/css">
</style>
<script>
    $(function () {
        $("tboby tr").addClass("datagrid-row");
        $("#purrgdg").datagrid({
            onBeforeLoad:function(){
                //初始化页脚数据
                var datar = $(this).datagrid("getData");
                datar.footer =new Array();
                datar.footer[0]=new Object();
                datar.footer[1]=new Object();
                datar.footer[1].prgid = '总金额：';
                datar.footer[1].prgmoney = 0;
                datar.footer[0].prgid = '本页金额：';
                datar.footer[0].prgmoney = 0;
                $(this).datagrid('loadData',JSON.parse(JSON.stringify(datar)));
            },
            onLoadSuccess:function (data) {
                var total =0;
                var totalAll =0;
                var rows = $("#purrgdg").datagrid('getRows');//获取本页数据
                var allrows =$("#purrgdg").datagrid('getData');//获取所有数据
                for(var j = 0; j<allrows.total; j++){
                    totalAll+=allrows.rows[j].prgmoney;
                }
                for (var i = 0; i < rows.length; i++) {
                    total += rows[i]['prgmoney'];
                }
                var footerRows = $('#purrgdg').datagrid('getFooterRows');
                footerRows[0]['prgmoney'] = total ;
                footerRows[1]['prgmoney'] = totalAll;
                $('#purrgdg').datagrid('reloadFooter');
                // $('#purrgdg').datagrid('reloadFooter',
                //     [
                //         {prgdate: "金额合计", prgmoney: 0}
                //     ]);
                $("a[name='details']").linkbutton({
                    width:30,iconCls:'icon-my_detail',plain:true
                });
                $("a[name='delete-one-purrg']").linkbutton({
                    onClick: function () {
                        var rowId = $(this).attr("id").substring(8);
                        $.messager.confirm("继续删除提示", "确定要删除选定的采购单吗？", function (a) {
                            if (a) {
                                $.post("pro-purchases-del", {rowsId: rowId}, function (r) {
                                    if (r.success) {
                                        $.messager.alert("SUCCESS", "删除成功！", "info");
                                        $("#purrgdg").datagrid({
                                            url:'allPurPaged',
                                            method:'post'
                                        });
                                        $("#purrgdg").datagrid("reload");
                                    } else {
                                        $.messager.alert("Failed", r.message, "error");
                                    }
                                });
                            }
                        });
                    },
                    width:30,iconCls:'icon-my_delete',plain:true
                });
                $("a[name='edit']").linkbutton({
                    width:30,iconCls:'icon-my_edit',plain:true
                });
            }
        });
        $("#reloadAllPurrg").linkbutton({
            onClick:function () {
                $("#purrgdg").datagrid({
                    url:'allPurrgPaged',
                    method:'post'
                });
                $("#purrgdg").datagrid("reload");
            }
        });
        //删除选中的分类(批量删除)
        $("#purrg-del-btn").linkbutton({onClick:function (){
                var rowsId = "";
                var rows = $("#purrgdg").datagrid('getSelections');
                if(rows.length>=1){
                    $.messager.confirm("继续删除提示","确定要删除选定的这些采购单吗？",function (t) {
                        if(t){
                            for(var i =0; i<rows.length;i++){
                                if(i==0){
                                    rowsId=rowsId+rows[i].purid;
                                }else {
                                    rowsId=rowsId+","+rows[i].purid;
                                }

                            }
                            $.post("pro-purchases-del",{rowsId:rowsId},function (r) {
                                if(r.success){
                                    $.messager.alert("SUCCESS","删除成功！","info");
                                    $("#purdg").datagrid({
                                        url:'allPurPaged',
                                        method:'post'
                                    });
                                    $("#purdg").datagrid("reload");
                                }else{
                                    $.messager.alert("Failed",r.message,"error");
                                }
                            });
                        }
                    });

                }else{
                    $.messager.alert("错误信息","未选中行！！！",'warning');
                }
            }});
    });
    function format(value,row,index){
        var str='<a id = \"'+"purrgShow"+row.prgid+'\" name="details" href="#" onclick="createDialogHut(\'detilsPurrg'+row.prgid+'\',\'查看采购详情\',\'to-form-pur-details\','+row.purid+')" class="easyui-linkbutton edit-btn"></a>'+
            '<a id =\"'+"purrgDel"+row.prgid+'\" name="delete-one-purrg" href="#"  class="easyui-linkbutton edit-btn"></a>'+
            '<a id = \"'+"purrgUpdate"+row.prgid+'\" name="edit" href="#" onclick="createDialogHut(\'editPurrg'+row.prgid+'\',\'编辑采购信息\',\'to-form-pur-update\','+row.purid+')" class="easyui-linkbutton edit-btn"></a>';
        return str;
    }
    function formatM(value,row,index){
        if(value!=null){
            return '<b style="color:red;">'+"￥"+value+'</b>';
        }else{
            return value;
        }
    }

</script>
<div class="easyui-layout" data-options="border:false,fit:true">
    <div data-options="region:'center',border:false">
        <table id="purrgdg" class="easyui-datagrid table-chance" style="width: auto;" data-options="fit:true,striped:true,height:350,fitColumns:true,
   autoRowHeight:true,nowrap:false,pagination:true,toolbar:'#tools-purrg',
pageList:[5,10,15,20],pageSize:10,url:'allPurrgPaged',method:'post',scrollbarSize:0,showFooter:true">
            <thead>
            <tr class="datagrid-header-row">
                <th data-options="field:'code',width:5,align:'center',checkbox:true">编码</th>
                <th data-options="field:'prgid',width:10,align:'center'">采购退货ID</th>
                <th data-options="field:'prgtheme',width:20,align:'center'">采购退货标题</th>
                <th data-options="field:'clientname',width:15,align:'center'">对应供应商</th>
                <th data-options="field:'purtheme',width:15,align:'center'">对应采购单</th>
                <th data-options="field:'purstatus',width:10,align:'center'">采购状态</th>
                <th data-options="field:'prgdate',width:15,align:'center'">退货日期</th>
                <th data-options="field:'prgmoney',width:20,align:'center'" formatter='formatM'>退回款</th>
                <%--<th data-options="field:'purstatus',width:15,align:'center'">采购状态</th>--%>
                <%--<th data-options="field:'manager',width:20,align:'center'" formatter="format">操作</th>--%>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <!--工具栏-->
        <div id="tools-purrg" style="height:10%;">
            <%--<a href="#" id="purrg-del-btn" class="easyui-linkbutton" data-options="iconCls:'icon-my_delete',plain:true">批量删除</a>--%>
            <a  id="reloadAllPurrg" class="easyui-linkbutton" data-options="iconCls:'icon-my_search',plain:true">查询所有</a>

            <input id="purrg-Search" class="easyui-searchbox" style="width: 45%;" data-options="searcher:function(value,name){
           $('#purrgdg').datagrid({
            url:'getAllPurrgBymh',
            method:'post',
            queryParams:{q:value,b:name}
            });
            $('#purrg-Search').searchbox('clear');
            $('#purrgdg').datagrid('reload');
           },prompt:'模糊查询通过采购主题供应商名称',menu:'#prglist'"/>
                <div id="prglist" class="easyui-menu" data-options="minWidth:100">
                    <div name="rg1">所有内容</div>
                    <div name="rg2">采购完成-待入库</div>
                    <div name="rg3">采购完成-已入库</div>
                </div>
            <!-- <a href="#" onclick="createDialog('hlQueryPurrg','高级查询','to-form-purrg-highLevel')" class="easyui-linkbutton">高级查询</a> -->
            <div style="text-align: right;height:5%;margin-right:8%;padding-bottom: 20px;">
                <a href="#" onclick="createDialog('newPurrg','新建采购退货单','to-form-purrg-add')" class="easyui-linkbutton" data-options="iconCls:'icon-mini_add2',border:true">新建采购退货单</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>

